package cn.com.gridinfo.sooc.core.expand.feedback.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.expand.feedback.bean.Suggestion;

/**
 * 反馈详情列表的adapter
 * Created by yingchunli on 2016/3/1.
 */
public class SuggestionInfoAdapter extends UltimateViewAdapter<SuggestionInfoAdapter.ViewHolder> {

    List<Suggestion> suggestionList;//回复反馈列表

    public SuggestionInfoAdapter(List<Suggestion> suggestionList) {
        this.suggestionList = suggestionList;
    }


    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view, false);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        //加载布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.expand_feedback_info_item, parent, false);

        return new ViewHolder(view, true);
    }

    @Override
    public int getAdapterItemCount() {
        return suggestionList.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position < getItemCount() &&
                (customHeaderView != null ? position <= suggestionList.size() : position < suggestionList.size())
                && (customHeaderView != null ? position > 0 : true)) {
            Suggestion suggestion = suggestionList.get(position);
            holder.uname.setText(suggestion.getUname());
            holder.content.setText(suggestion.getHfnr());
            holder.time.setText(suggestion.getInput_time());
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
    }

    public void loadmore(List<Suggestion> list) {
        suggestionList.addAll(list);
        notifyDataSetChanged();
    }

    public void refresh(List<Suggestion> list) {
        clear(suggestionList);
        suggestionList.addAll(list);
        notifyDataSetChanged();
    }

    //ViewHolder
    public class ViewHolder extends UltimateRecyclerviewViewHolder {
        TextView content, time, uname;

        public ViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                //反馈内容
                content = (TextView) itemView.findViewById(R.id.content);
                //反馈时间
                time = (TextView) itemView.findViewById(R.id.time);
                //回复人
                uname = (TextView) itemView.findViewById(R.id.uname);
            }
        }
    }


}
